package com.novasoftware.novagooglemap.activity;

import com.novasoftware.novagooglemap.R;
import com.novasoftware.novagooglemap.db.builder.NovaCategoryBuilder;
import com.novasoftware.novagooglemap.db.builder.StudentBuilder;
import com.novasoftware.novagooglemap.db.entity.NovaCategory;
import com.novasoftware.novagooglemap.db.entity.Student;
import com.novasoftware.novagooglemap.framework.activity.BaseActivity;
import com.novasoftware.novagooglemap.framework.inteface.ISave;
import com.novasoftware.novagooglemap.framework.listener.SaveListener;
import com.novasoftware.novagooglemap.framework.util.ImageHelper;
import com.novasoftware.novagooglemap.service.SQLLiteServiceBase;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

public class CategoryEdit extends BaseActivity implements ISave<NovaCategory> {

	private SQLLiteServiceBase<NovaCategory> _service;
	private NovaCategory _novaCategory;
	
	private EditText txtName;
	private EditText txtCaseStudy;
	private ImageButton txtImage;
	private Button btnSave;
	private Button btnClose;
	
	@Override
	protected boolean IsHiderUI() {
		return false;
	}
	
	@Override
	protected void InitializeService() {
		_service = new SQLLiteServiceBase<NovaCategory>(CategoryEdit.this, new NovaCategoryBuilder());
	}
	
	@Override
	protected int getContent() {
		return R.layout.category_edit;
	}

	@Override
	protected void LocalizeControls() {
		txtCaseStudy = (EditText)findViewById(R.id.txtCaseStudy);
		txtName = (EditText)findViewById(R.id.txtName);
		txtImage= (ImageButton)findViewById(R.id.txtImage);
		btnSave = (Button)findViewById(R.id.btnSave);
		btnClose = (Button)findViewById(R.id.btnClose);
	}
	
	@Override
	protected void RegisterEvents() {
		btnSave.setOnClickListener(new SaveListener<NovaCategory>(this));
		btnClose.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();
			}
		});
		txtImage.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				ImageHelper.OpenCamera(CategoryEdit.this);
			}
		});
	}

	@Override
	public NovaCategory UpdateEntity() {
		if(_novaCategory==null)
			_novaCategory = new NovaCategory();
		_novaCategory.CaseStudy = 10;
		_novaCategory.Name = txtName.getEditableText().toString();
		_novaCategory.ImageId = R.drawable.ic_launcher;
		return _novaCategory;
	}
  
	@Override
	public Boolean Save(NovaCategory entity)
	{
		_service.Save(entity);
		return true;
	}

}
